package com.skateboard.reelviewtest.rotate;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.skateboard.reelviewtest.R;


/**
 * @作者： xuze
 * @时间： 2020/11/27 2:12 PM
 * @描述： 属性动画 翻装变形；
 */
public class MyDialog2 extends Dialog {


    private Context context;

    RelativeLayout container;
    LinearLayout layout1;
    LinearLayout layout2;



    //接口回调传递参数
    private OnClickListenerInterface mListener;
//
    private String strContent;


    private int centerX;
    private int centerY;
    private int depthZ = 1;
    private int duration = 2000;
    private Animation rotateAnimation1;
    private Animation rotateAnimation2;
    private Animation rotateAnimation3;
    private Animation rotateAnimation4;
    private Animation scaleAnimation;
    AnimationSet setAnimation;

    private boolean isOpen = false;

    public interface OnClickListenerInterface {

        /**
         * 确认,
         */
        void doConfirm();

        /**
         * 取消
         */
        public void doCancel();
    }

    public MyDialog2(Context context) {
        super(context);
        this.context = context;
    }

    public MyDialog2(Context context, String content) {
        super(context);
        this.context = context;
        this.strContent = content;

    }
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            startAnimation();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉系统的黑色矩形边框
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dialog_my, null);
        setContentView(view);
        container=findViewById(R.id.container);
        layout1=findViewById(R.id.layout_1);
        layout2=findViewById(R.id.layout_2);

        init();
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        handler.sendEmptyMessageDelayed(0,100);
        //startAnimation();
    }

    public void init() {
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
        lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
        lp.height = (int) (d.heightPixels * 1); // 高度设置为屏幕的0.6
        dialogWindow.setAttributes(lp);
        //setCanceledOnTouchOutside(false);
        //setCancelable(true);


    }




    private void startAnimation() {

        AnimatorSet set=new AnimatorSet();
        set.playTogether(
                ObjectAnimator.ofFloat(container,"rotationY",0,360)//绕X轴翻转
        );
        set.setDuration(2*1000).start();//时间

    }




}